/***************************************************************************
 创建者: 华磊
 开始时间: 2019.11.20
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:焊接开始实现
 *
 *                                                                         *
 ***************************************************************************/

#ifndef WELDSTARTINSTRUCTIONLOGIC_H
#define WELDSTARTINSTRUCTIONLOGIC_H


#include "ioinstruction.h"
#include "programset.h"
#include "instructionEnum.h"
#include "robotio.h"
#include "GeneralDefine.h"

class ProgramEngine;

class WeldStartInstructionLogic
{
public:
    WeldStartInstructionLogic(QString configFilePathIn,int robotIdIn,ProgramSet* programSetIn,RobotIo* ioControllerIn,
                              ProgramEngine* programEngineIn);
public:
    E_PROGRAM_LOOP_RESULT startWeldStart(int programNum,WeldStartInstruction weldStartInstruct);
    E_PROGRAM_LOOP_RESULT startWeldEnd(int programNum,WeldEndInstruction weldEndInstruct);

    int getWeldDebugStatusInfo(struct WeldCraftStatusInfo& infoOut);
    int weldDebugOperation(enum E_WELD_TEST typeIn,bool control);
    int setWeldCollisionCheck(bool isCheck);

    int weldWorkingMonitor();
    int stopWeld();
    bool isInWeldingStatus();



    int setVirtualMode(bool isVirtualControlIn);
    bool getWeldIsVirtualStatus();
    /**
     * @brief getWeldProperty 获取焊接属性列表
     * @param configListOut
     * @return
     */
    int getWeldProperty(std::vector<WeldProperty> &configListOut);

    /**
     * @brief changeWeldPropertConfig  修改保存焊接属性
     * @param weldProperty
     * @return
     */
    int changeWeldPropertConfig(struct WeldProperty weldProperty);

    /**
     * @brief getWeldCondition  获取焊接条件列表
     * @param configListOut
     * @return
     */
    int getWeldCondition(std::vector<WeldCondition> &configListOut);

    /**
     * @brief changeWeldConditionConfig 修改保存焊接条件
     * @param weldCondition
     * @return
     */
    int changeWeldConditionConfig(struct WeldCondition weldCondition);

    /**
     * @brief getWeldSystemInfo 获取弧焊系统信息
     * @param weldSystemInfo
     * @return
     */
    int getWeldSystemInfo(struct WeldSystemInfo &weldSystemInfo);

    /**
     * @brief changeWeldSystemInfo 修改弧焊系统信息
     * @param configIn
     * @return
     */
    int changeWeldSystemInfo(struct WeldSystemInfo configIn);




private:
    int readConfigFile(QString filePathIn, QString &readComent);

    int readWeldProperty(QString filePathIn,std::vector<WeldProperty> &configListOut, QString &readComent);
    int writeWeldPropertConfig(QString filePathIn,struct WeldProperty weldProperty);
    int readWeldCondition(QString filePathIn,std::vector<WeldCondition> &configListOut, QString &readComent);
    int writeWeldConditionConfig(QString filePathIn,struct WeldCondition weldCondition);

     int readWeldSystemInfo(QString filePathIn, struct WeldSystemInfo &weldSystemInfo,
                            bool &isUseArcWeldModuleOut, QString &readComent);
     int writeWeldSystemInfo(QString filePathIn, struct WeldSystemInfo &configIn);

     int readDiDoSetting(QString filePathIn, QString &readComent);

     int getWeldConditionInfoWithIndex(int index,struct WeldCondition &weldCondition);
     int getWeldPropertyWithIndex(int index, struct WeldProperty &weldPropertyOut);
     double getVoltageFeedback();
     double getAmpFeedback();
     double getVoltageFeedbackByAi(double ai);
     double getAmpFeedbackByAi(double ai);
     double getAoByVoltageCommand(double voltageCommand);
     double getAoByAmpCommand(double ampCommand);

    /**
     * @brief addMsg  , 添加消息反馈
     * @param messageLevel
     * @param componentName
     * @param messageType
     * @param messageCode
     * @param robotId
     * @param parameter1
     * @param parameter2
     * @param parameter3
     * @param parameter4
     */
    void addMsg( int messageLevel,
                 std::string componentName,
                 std::string messageType,
                 int messageCode,
                 int robotId,
                 int parameter1 = 0,
                 int parameter2 = 0,
                 int parameter3 = 0,
                 int parameter4 = 0,
                 QString message= "");
private:
    int robotId;
    ProgramSet* programSet;
    RobotIo* ioController;
    ProgramEngine* programEngine;
    QString configFilePath;
    QString weldSystemInfofilePath;

    struct WeldCondition weldConditionModel;

    int collision_normal_logic;
    int enable_collision_check;
    int di_collision;
    int do_weld_start; //起弧信号
    int do_reverse_wirefeeding; //反向送丝信号
    int di_weld_startSucceful; //起弧成功信号
    int do_positive_wirefeeding; //正向送丝信号
    int do_gas_detection; //气体检测信号
    int di_find_position; //机器人寻位信号
    int ao_weld_voltage; //给定电压信号
    int ao_weld_Amp; //给定电流信号
    int ai_weld_voltageMes; //焊接电压信号（反馈)
    int ai_weld_IrealMes; //焊接电流信号（反馈）
    double ratio_ao_weld_voltage; //比例系数
    double ratio_ao_weld_Amp; //比例系数
    double ratio_ai_weld_voltageMes; //比例系数
    double ratio_ai_weld_IrealMes; //比例系数
    double minimum_ao_weld_voltage;//参考麦格米勒的焊机定义图标
    double minimum_ao_weld_Amp;
    double minimum_ai_weld_voltageMes;
    double minimum_ai_weld_IrealMes;

    WeldSystemInfo weldSystemInfomation;
    std::vector<WeldProperty> weldPropertyList;
    std::vector<WeldCondition> weldConditionList;
    bool isVirtualControl;
    bool isInWelding;
    QMutex usingMutex;
    bool isUseArcWeldModule;
};

#endif // WELDSTARTINSTRUCTIONLOGIC_H
